import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import department from '@/router/modules/department'
 import employees from '@/router/modules/employees.js'
 import approvals from '@/router/modules/approvals'
 import attendances from '@/router/modules/attendances'
 import permissions from '@/router/modules/permissions'
 import salarys from '@/router/modules/salarys'
 import settings from '@/router/modules/settings'
 import social_securitys from '@/router/modules/social_securitys'
// 创建动态路由
export const asyncRoutes=[
  // 放动态路由对象 的模块
  department,
  settings,
  employees,
  permissions,

  approvals,
  attendances,
  salarys,
  social_securitys,

]
// 静态路由
export const constantRoutes = [
  // {
  //   path: '/import',
  //   component: () => import('@/views/import/index.vue'),
  //   hidden: true
  // },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // 合并路由
  routes: [...constantRoutes,...asyncRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
